"""
数据模型定义
"""
from typing import List, Optional, Dict, Any
from pydantic import BaseModel, Field
from datetime import datetime
from enum import Enum


class AuditResult(str, Enum):
    """审核结果枚举"""
    PASS = "PASS"
    REJECT = "REJECT"
    MANUAL = "MANUAL"  # 需要人工审核


class AuditRequest(BaseModel):
    """审核请求模型"""
    post_id: int = Field(..., description="帖子ID")
    content: str = Field(..., description="帖子内容")
    title: Optional[str] = Field(None, description="帖子标题")
    images: Optional[List[str]] = Field(default=[], description="图片URL列表")
    author_id: int = Field(..., description="作者ID")
    timestamp: datetime = Field(default_factory=datetime.now, description="请求时间")
    
    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }


class SensitiveWordResult(BaseModel):
    """敏感词检测结果"""
    has_sensitive: bool = Field(..., description="是否包含敏感词")
    sensitive_words: List[str] = Field(default=[], description="检测到的敏感词")
    confidence: float = Field(..., description="置信度")


class TextClassificationResult(BaseModel):
    """文本分类结果"""
    category: str = Field(..., description="分类结果")
    confidence: float = Field(..., description="置信度")
    is_normal: bool = Field(..., description="是否为正常内容")


class SentimentAnalysisResult(BaseModel):
    """情感分析结果"""
    sentiment: str = Field(..., description="情感倾向: positive/negative/neutral")
    confidence: float = Field(..., description="置信度")
    score: float = Field(..., description="情感分数 [-1, 1]")


class ImageAuditResult(BaseModel):
    """图片审核结果"""
    is_safe: bool = Field(..., description="图片是否安全")
    violations: List[str] = Field(default=[], description="违规类型")
    confidence: float = Field(..., description="置信度")


class AuditResponse(BaseModel):
    """审核响应模型"""
    post_id: int = Field(..., description="帖子ID")
    audit_result: AuditResult = Field(..., description="审核结果")
    confidence: float = Field(..., description="总体置信度")
    reasons: List[str] = Field(default=[], description="拒绝原因")
    details: Dict[str, Any] = Field(default={}, description="详细审核信息")
    processed_at: datetime = Field(default_factory=datetime.now, description="处理时间")
    
    class Config:
        json_encoders = {
            datetime: lambda v: v.isoformat()
        }


class AuditRecord(BaseModel):
    """审核记录模型"""
    id: Optional[int] = None
    post_id: int
    audit_result: str
    confidence: float
    reasons: Optional[str] = None  # JSON字符串
    details: Optional[str] = None  # JSON字符串
    created_at: Optional[datetime] = None
    updated_at: Optional[datetime] = None
